﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AssetAllocationSystem.Models;
using NHibernate;
using NHibernate.Criterion;

namespace AssetAllocationSystem.Repositories
{
    public class VendorRepository : RepositoryBase<Vendor>
    {
        private ISession session;
        public VendorRepository(ISession session)
            : base(session)
        {
            this.session = session;
        }
        //public IList<Vendor> FindById(Guid vendorId)
        //{
        //    ISession session = base.CreateSession();

        //    var vendor = DetachedCriteria
        //        .For<Vendor>()
        //        .Add(Restrictions.Eq("Id", vendorId))
        //        .GetExecutableCriteria(session)
        //        .List<Vendor>();

        //    return vendor;
        //}

        public IList<Vendor> FindByName(string name)
        {
            var vendors =
                DetachedCriteria
                    .For<Vendor>()
                    .Add(Restrictions.Like("Name", name))
                    .GetExecutableCriteria(session)
                    .List<Vendor>();

            return vendors;
        }
    }
}